import { defHttp } from '/@/utils/http/axios';

enum Api {
  AddResource = '/admin/resource/save',
  GetResourceList = '/admin/resource/page',
  EditResource = '/admin/resource/update',
  GetByCodeResource = '/admin/resource/getByCode/',
  GetOptionsResource = '/admin/resource/getOptions',
  DelResourceById = '/admin/resource/delById',
  CommonDownLoad = '/model/module/fileDownLoad',
}

export interface ResourceParam {
  classify: number;
  code: string;
  name: string;
  summary?: string;
  data: string;
  id?: string;
}

interface ResourceList {
  current: number;
  size: number;
  classify?: number;
  code?: string;
}

export const addResourceServe = (params: ResourceParam) =>
  defHttp.post<any>({ url: Api.AddResource, params });

export const getResourceList = (params: ResourceList) =>
  defHttp.get<any>({ url: Api.GetResourceList, params });

export const editResourceServe = (params: ResourceParam) =>
  defHttp.post<any>({ url: Api.EditResource, params });

export const delResourceList = (id: string) =>
  defHttp.post<any>({ url: Api.DelResourceById + `/${id}` });

export const CommonDownLoad = (params: any) =>
  defHttp.post<any>(
    {
      url: Api.CommonDownLoad,
      params,
      responseType: 'arraybuffer',
      // headers: {
      //   'Content-Type': ContentTypeEnum.FORM_DATA,
      // },
    },
    { isTransformResponse: false, isReturnNativeResponse: true },
  );

export const getResourceInfo = (code: string) =>
  defHttp.get<any>({ url: Api.GetByCodeResource + code });
export const getOptionsResource = (params: any) =>
  defHttp.get<any>({ url: Api.GetOptionsResource, params });
